import axios from './router/axios';
import VueAxios from 'vue-axios';
import App from './App';
import router from './router/router';
import './permission'; // 权限
import './error'; // 日志
import './cache';//页面缓存
import store from './store';
import {loadStyle} from './util/util'
import * as urls from '@/config/env';
import Element from 'element-ui';
import {
  iconfontUrl,
  iconfontVersion
} from '@/config/env';
import i18n from './lang'; // Internationalization
import './styles/common.scss';
import basicBlock from './components/basic-block/main';
import basicContainer from './components/basic-container/main';
import thirdRegister from './components/third-register/main';
import AvueUeditor from 'avue-plugin-ueditor'
import VueQuillEditor from 'vue-quill-editor'
import website from '@/config/website';
import crudCommon from '@/mixins/crud';
import clipboard from 'clipboard';
import Vue from 'vue';
import VueBus from 'vue-bus';
// 业务组件
import tenantPackage from './views/system/tenantpackage';
import './styles/iconfont.css'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import 'element-ui/lib/theme-chalk/index.css';

axios.defaults.withCredentials = false
Vue.use(VueBus);

// 注册全局crud驱动
window.$crudCommon = crudCommon;
// 加载Vue拓展
Vue.use(router);
Vue.use(VueAxios, axios);
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(window.AVUE, {
  size: 'small',
  tableSize: 'small',
  calcHeight: 65,
  i18n: (key, value) => i18n.t(key, value)
});
// 注册全局容器
Vue.component('basicContainer', basicContainer);
Vue.component('basicBlock', basicBlock);
Vue.component('thirdRegister', thirdRegister);
// Vue.component('avueUeditor', avueUeditor);
Vue.use(AvueUeditor);
Vue.use(VueQuillEditor)
Vue.component('tenantPackage', tenantPackage);
// 千分符格式化
Vue.filter('thousandSeparator', function (num) {
  if (num ===undefined) return ''
  // 字符串不转换
  if (num === '' || typeof num == 'string') return num
  let s = num.toString();
  let div = s.indexOf('.');
  let sign = (num < 0) ? '-' : '';
  let intPart = (div == -1) ? s : s.substring(0, div);
  let dotPart = (div == -1) ? '' : s.substring(div);
  let finalIntPart = '';
  while (intPart.length > 3) {
    finalIntPart = ',' + intPart.substring(intPart.length - 3) + finalIntPart;
    intPart = intPart.substring(0, intPart.length - 3);
  }
  return sign + intPart + finalIntPart + dotPart;
})
Vue.directive( 'peach',{
  bind (el, binding) {
    const {
      value, //
      arg // 参数event  v-peach:event
    } = binding

    /*
      modifiers, // 修饰符
    */

    el.addEventListener('click', () => {
      if (arg === 'event') {
        const { category, action } = value
        window._hmt.push(['_trackEvent', category, action])
      } else if (arg === 'pagevt') {
        const { category, action } = value
        window._hmt.push(['_trackPageview', category, action])
      }
    })
  }
})
// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key];
});
// 加载website
Vue.prototype.website = website;
// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele));
});

Vue.config.productionTip = false;
Vue.config.devtools = true
//全局引入复制插件
Vue.prototype.clipboard = clipboard;
new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app');

// //引入百度统计
// router.afterEach(( to, from, next ) => {
//   setTimeout(()=>{
//     var _hmt = _hmt || [];
//     (function() {
//       var hm = document.createElement("script");
//       hm.src = "https://hm.baidu.com/hm.js?dbe1213c9ec43551ce019ca8bc58b030";
//       var s = document.getElementsByTagName("script")[0];
//       s.parentNode.insertBefore(hm, s);
//     })();
//   },0);
// });


